program main

 use omp_lib
!
  implicit none

  integer id
  integer nthreads
!  integer omp_get_num_procs
!  integer omp_get_num_threads
!  integer omp_get_thread_num

  call timestamp ( )

  write ( *, '(a)' ) ' '
  write ( *, '(a)' ) 'HELLO'
  write ( *, '(a)' ) '  FORTRAN90 version'
  write ( *, '(a)' ) ' '
  write ( *, '(a)' ) '  An OpenMP sample program.'
  write ( *, '(a)' ) ' '
  write ( *, '(a)' ) '  Have each parallel thread identify itself.'
  write ( *, '(a)' ) ' '
  write ( *, '(a)' ) '  The number of processors available:'
  write ( *, '(a,i8)' ) '  OMP_GET_NUM_PROCS () = ', omp_get_num_procs ( )

  nthreads = 4

  write ( *, '(a)' ) ' '
  write ( *, '(a,i8,a)' ) '  Call OMP_SET_NUM_THREADS, and request ', &
    nthreads, ' threads.'

  call omp_set_num_threads ( nthreads )

  write ( *, '(a)' ) ' '
  write ( *, '(a)' ) '  Calling OMP_GET_NUM_THREADS outside a '
  write ( *, '(a)' ) '  parallel region, we get the number of'
  write ( *, '(a,i8)' ) '  threads is ', omp_get_num_threads ( )
  write ( *, '(a)' ) ' '
!
!  Note that the call to OMP_GET_NUM_THREADS will always return 1
!  if called outside a parallel region!
!
!$OMP parallel private ( id )

  id = omp_get_thread_num ( )

  write ( *, '(a,i3)' ) '  This is process ', id

  if ( id == 0 ) then

    write ( *, '(a)' ) ' '
    write ( *, '(a)' ) '  Calling OMP_GET_NUM_THREADS inside a '
    write ( *, '(a)' ) '  parallel region, we get the number of'
    write ( *, '(a,i3)' ) '  threads is ', omp_get_num_threads ( )
    write ( *, '(a)' ) ' '

  end if

!$OMP end parallel

  write ( *, '(a)' ) ' '
  write ( *, '(a)' ) 'HELLO'
  write ( *, '(a)' ) '  Normal end of execution.'

  write ( *, '(a)' ) ' '
  call timestamp ( )

  stop
end
subroutine timestamp ( )

  implicit none

  character ( len = 8 ) ampm
  integer d
  character ( len = 8 ) date
  integer h
  integer m
  integer mm
  character ( len = 9 ), parameter, dimension(12) :: month = (/ &
    'January  ', 'February ', 'March    ', 'April    ', &
    'May      ', 'June     ', 'July     ', 'August   ', &
    'September', 'October  ', 'November ', 'December ' /)
  integer n
  integer s
  character ( len = 10 )  time
  integer values(8)
  integer y
  character ( len = 5 ) zone

  call date_and_time ( date, time, zone, values )

  y = values(1)
  m = values(2)
  d = values(3)
  h = values(5)
  n = values(6)
  s = values(7)
  mm = values(8)

  if ( h < 12 ) then
    ampm = 'AM'
  else if ( h == 12 ) then
    if ( n == 0 .and. s == 0 ) then
      ampm = 'Noon'
    else
      ampm = 'PM'
    end if
  else
    h = h - 12
    if ( h < 12 ) then
      ampm = 'PM'
    else if ( h == 12 ) then
      if ( n == 0 .and. s == 0 ) then
        ampm = 'Midnight'
      else
        ampm = 'AM'
      end if
    end if
  end if

  write ( *, '(a,1x,i2,1x,i4,2x,i2,a1,i2.2,a1,i2.2,a1,i3.3,1x,a)' ) &
    trim ( month(m) ), d, y, h, ':', n, ':', s, '.', mm, trim ( ampm )
pause
  return
end
